package com.example.spring2304;

import com.example.spring2304.stbu.Customer;
import com.example.spring2304.stbu.CustomerByAno;
import com.example.spring2304.stbu.MyConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
@RequestMapping("/test")
public class Spring2304Application {

    public static void main(String[] args) {
        SpringApplication.run(Spring2304Application.class, args);
//        ApplicationContext context = new ClassPathXmlApplicationContext("myConfig.xml");
//        Customer cu = (Customer) context.getBean("cu2");
//        System.out.println("id = " + cu.getId() + "，姓名=" + cu.getUsername() + ",密码=" + cu.getPassword());

//        基于注解方式转载bean
        ApplicationContext con = new AnnotationConfigApplicationContext(MyConfig.class);
        CustomerByAno ano = con.getBean(CustomerByAno.class);
        System.out.println("id = " + ano.getId() + "，姓名=" + ano.getUsername() + ",密码=" + ano.getPassword());


    }

    @GetMapping("/hello04")
    public String hello04() {
        return "今天天气很凉快";
    }

}
